<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/9/13
  Time: 16:56
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>请求中JSON格式的参数转为JAVA对象</title>
    <script src="/js/jquery-2.1.1.min.js"></script>
    <script>
        $(function () {
            $("#btn").click(function () {
                var name=$("#name").val();
                var age=$("#age").val();
                //把参数转为json的字符串
                var param = JSON.stringify({"name":name,"age":age});
               /*参数转为jackson格式*/
                $.ajax({
                    url:"/c8/addstudent2",
                    contentType:"application/json",/*请求的格式*/
                    type:"post",
                    data:param,
                    success:function (data) {
                        console.log(data);
                    }
                })

            })

        })
    </script>
</head>
<body>
姓名：<input id="name"><br>
年龄：<input id="age"><br>
<%--因为不是表单提交，不需要submit--%>
<input type="button" value="提交" id="btn">
</body>
</html>
<%--ajax请求要引入js文件--%>